package com.bs.visitservice.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class ParamUtils {

    /**
     * 获取分页对象
     * @param cond
     * @return
     */
    public static IPage getPage(Map cond){

        Integer pageIndex = null;
        Integer pageSize = null;
        if(cond.get("pageIndex") == null || cond.get("pageSize")==null){
            pageIndex = 1;
            pageSize = 10000;
        }else{
            pageIndex = (Integer)cond.get("pageIndex");
            pageSize = (Integer)cond.get("pageSize");
        }
        IPage page = new Page(pageIndex,pageSize);
        return page;
    }

    /**
     * 从request获取tokenId
     * @param request
     * @return
     */
    public static String getToken(HttpServletRequest request){
        String token = request.getHeader("tokenId");
        if(StringUtils.isBlank(token)){
            token = request.getParameter("tokenId");
        }
        return token;
    }

}
